<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
 <head>
  <title>商品</title>
  <t:base type="jquery,easyui,tools,DatePicker"></t:base>
 </head>
 <body style="overflow-y: auto" scroll="no">
			<table style="width: 100%" cellpadding="0" cellspacing="1" class="formtable">
				<tr>
					<td align="right">
						<label class="Validform_label">
							商品编码:
						</label>
					</td>
					<td class="value">
						<span class="">${mallProductPage.productcode}</span>
					</td>
					<td align="right">
						<label class="Validform_label">
							商品名称:
						</label>
					</td>
					<td class="value">
						<span class="">${mallProductPage.productname}</span>
					</td>
					<%--<td align="right">
						<label class="Validform_label">
							sellerproductcode:
						</label>
					</td>
					<td class="value">
						<input class="inputxt" id="sellerproductcode" name="sellerproductcode" ignore="ignore"
							   value="${mallProductPage.sellerproductcode}">
						<span class="Validform_checktip"></span>
					</td>--%>
				<%--<tr>
					<td align="right">
						<label class="Validform_label">
							shopid:
						</label>
					</td>
					<td class="value">
						<input class="inputxt" id="shopid" name="shopid"
							   value="${mallProductPage.shopid}" datatype="n">
						<span class="Validform_checktip"></span>
					</td>
				</tr>--%>
			<%--	<tr>
					<td align="right">
						<label class="Validform_label">
							productcategoryid:
						</label>
					</td>
					<td class="value">
						<input class="inputxt" id="productcategoryid" name="productcategoryid"
							   value="${mallProductPage.productcategoryid}" datatype="n">
						<span class="Validform_checktip"></span>
					</td>
				</tr>--%>
					<td align="right">
						<label class="Validform_label">
							商品类型:
						</label>
					</td>
					<td class="value">
						<span class=" ">
							<input type="hidden" id="product_saletype" value="${mallProductPage.saletype}">
							<c:if test="${mallProductPage.saletype == 0}">
								线上商品
							</c:if>
							<c:if test="${mallProductPage.saletype == 1}">
								本地商品
							</c:if>
							<c:if test="${mallProductPage.saletype == 2}">
								充值商品
							</c:if>
						</span>
					</td>
					<%--<td align="right">
						<label class="Validform_label">
							商品类型:
						</label>
					</td>
					<td class="value">
						<span class=" ">${mallProductPage.saletype}</span>
					</td>--%>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							商品简介:
						</label>
					</td>
					<td class="value" colspan="3">
						<textarea class="inputxt" id="description"  name="description" ignore="ignore">${mallProductPage.description}
						</textarea>
						<span class=" "></span>
					</td>
					<td align="right">
						<label class="Validform_label">
							关键字:
						</label>
					</td>
					<td class="value" colspan="3">
						<textarea class="inputxt" id="keywords" name="keywords" ignore="ignore">${mallProductPage.keywords}</textarea>
						<span class=" "></span>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							商品原价:
						</label>
					</td>
					<td class="value">
						<span class=" ">${mallProductPage.originalprice}</span>
					</td>
					<td align="right">
						<label class="Validform_label">
							商品现价:
						</label>
					</td>
					<td class="value">
						<input type="hidden" id="product_price" value="${mallProductPage.price}">
						<span class=" ">${mallProductPage.price}</span>
					</td>
				<%--<tr>
					<td align="right">
						<label class="Validform_label">
							discount:
						</label>
					</td>
					<td class="value">
						<input class="inputxt" id="discount" name="discount"
							   value="${mallProductPage.discount}" datatype="d">
						<span class=" "></span>
					</td>
				</tr>--%>
					<td align="right">
						<label class="Validform_label">
							库存:
						</label>
					</td>
					<td class="value">
						<span class=" ">${mallProductPage.stockamount}</span>
					</td>
					<td align="right">
						<label class="Validform_label">
							最小金额:
						</label>
					</td>
					<td class="value">
						<span class=" ">${mallProductPage.minmoney}</span>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							最大金额:
						</label>
					</td>
					<td class="value">
						<input type="hidden" id="product_maxmoney" value="${mallProductPage.maxmoney}">
						<span class=" ">${mallProductPage.maxmoney}</span>
					</td>
					<td align="right">
						<label class="Validform_label">
							上架时间:
						</label>
					</td>
					<td class="value">
						<span class=" "><fmt:formatDate value='${mallProductPage.startdatetime}' type="date" pattern="yyyy-MM-dd hh:mm:ss"/> </span>
					</td>
					<td align="right">
						<label class="Validform_label">
							最后编辑时间:
						</label>
					</td>
					<td class="value">
						<span class=" "><fmt:formatDate value='${mallProductPage.enddatetime}' type="date" pattern="yyyy-MM-dd hh:mm:ss"/></span>
					</td>
					<td align="right">
						<label class="Validform_label">
							创建时间:
						</label>
					</td>
					<td class="value">
						<span class=" "><fmt:formatDate value='${mallProductPage.createtime}' type="date" pattern="yyyy-MM-dd hh:mm:ss"/></span>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							状态:
						</label>
					</td>
					<td class="value">
						<span class=" ">
							<c:if test="${mallProductPage.status == 0}">
								未上架
							</c:if>
							<c:if test="${mallProductPage.status == 1}">
								在售
							</c:if>
							<c:if test="${mallProductPage.status == 2}">
								下架
							</c:if>
						</span>
					</td>
					<td align="right">
						<label class="Validform_label">
							图片:
						</label>
					</td>
					<td class="value" colspan="3">
						<img src="${mallProductPage.thumbnailurl}" width="200px" height="100px">
					</td>
					<td align="right">
						<label class="Validform_label">
							平台约束:
						</label>
					</td>
					<td class="value">
						<span class=" ">
							<c:if test="${mallProductPage.isdelete == 0}">
								启用
							</c:if>
							<c:if test="${mallProductPage.isdelete == 1}">
								禁用
							</c:if>
						</span>
					</td>
				</tr>
				<%--<tr>
					<td align="right">
						<label class="Validform_label">
							hasspec:
						</label>
					</td>
					<td class="value">
						<input class="inputxt" id="hasspec" name="hasspec"
							   value="${mallProductPage.hasspec}" datatype="n">
						<span class=" "></span>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							defaultspecid:
						</label>
					</td>
					<td class="value">
						<input class="inputxt" id="defaultspecid" name="defaultspecid" ignore="ignore"
							   value="${mallProductPage.defaultspecid}" datatype="n">
						<span class=" "></span>
					</td>
				</tr>--%>
			</table>
			<span>店铺信息</span>
			<table style="width: 100%" cellpadding="0" cellspacing="1" class="formtable">
				<tr>
					<td align="right">
						<label class="Validform_label">
							店铺名称:
						</label>
					</td>
					<td class="value">
						<span class=" ">${mallProductPage.mallShopEntity.shopname}</span>
					</td>
					<td align="right">
						<label class="Validform_label">
							公司名称:
						</label>
					</td>
					<td class="value" colspan="3">
						<span class=" ">${mallProductPage.mallShopEntity.companyname}</span>
					</td>
					<td align="right">
						<label class="Validform_label">
							联系人:
						</label>
					</td>
					<td class="value">
						<span class=" ">${mallProductPage.mallShopEntity.contactperson}</span>
					</td>
					<td align="right">
						<label class="Validform_label">
							联系方式:
						</label>
					</td>
					<td class="value">
						<span class=" ">${mallProductPage.mallShopEntity.phonenumber}</span>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							联系地址:
						</label>
					</td>
					<td class="value" colspan="8">
						<span class=" ">${mallProductPage.mallShopEntity.shopname}</span>
					</td>
				</tr>
			</table>
			<span>折扣信息</span>
			<form id="subsidy" action="mallSubsidyController.do?save" method="post">
				<table style="width: 100%" cellpadding="0" cellspacing="1" class="formtable">
					<input type="hidden" name="id" value="${subsidy.id}">
					<tr>
						<td align="right">
							<label class="Validform_label">
								补贴类型:
							</label>
						</td>
						<td>
							<select id="subsidyType" name="subsidytype" datatype="*">
								<option value="0" <c:if test="${subsidy.subsidytype == 0}"> selected </c:if>>不补贴</option>
								<option value="1" <c:if test="${subsidy.subsidytype == 1}"> selected </c:if>>按金额</option>
								<option value="2" <c:if test="${subsidy.subsidytype == 2}"> selected </c:if>>按折扣</option>
								<option value="3" <c:if test="${subsidy.subsidytype == 3}"> selected </c:if>>满减</option>
							</select>
						</td>
						<td align="right">
							<label class="Validform_label">
								补贴额度(件):
							</label>
						</td>
						<td class="value" id="subsidyVal_td">
							<c:if test="${subsidy.subsidytype != 3}">
								<input class="inputxt" id="subsidyVal" nullmsg="请填写补贴额度" name="subsidyval" value="${subsidy.subsidyDetailEntities[0].subsidyval}" datatype="/^([1-9]\d*|0)(\.\d{1,2})?$/,subsidy">
							</c:if>
							<c:if test="${subsidy.subsidytype == 3}">
								<table id="subsidyVal_table">
									<c:forEach var="subsidyDetail" items="${subsidy.subsidyDetailEntities}" varStatus="status">
										<c:choose>
											<c:when test="${status.index == 0}">
												<tr>
													<td>最小金额:<input class="inputxt" type="text" value="${subsidyDetail.minmoney}"  datatype="/^([1-9]\d*|0)(\.\d{1,2})?$/"/></td>
													<td>最大金额:<input class="inputxt" type="text" value="${subsidyDetail.maxmoney}" datatype="/^([1-9]\d*|0)(\.\d{1,2})?$/,maxMoneyCompare"/></td>
													<td>补贴金额:<input class="inputxt" type="text" value="${subsidyDetail.subsidyval}"  datatype="/^([1-9]\d*|0)(\.\d{1,2})?$/,subsidy"></td>
													<td><input type="button" onclick="mallProductSubsidyModule.addMjTd()" value="添加"/></td>
												</tr>
											</c:when>
											<c:otherwise>
												<tr>
													<td>最小金额:<input class="inputxt" type="text"  value="${subsidyDetail.minmoney}" datatype="/^([1-9]\d*|0)(\.\d{1,2})?$/,minMoneyCompare"/></td>
													<td>最大金额:<input class="inputxt" type="text"  value="${subsidyDetail.maxmoney}" datatype="/^([1-9]\d*|0)(\.\d{1,2})?$/,maxMoneyCompare"/></td>
													<td>补贴金额:<input class="inputxt" type="text" value="${subsidyDetail.subsidyval}"  datatype="/^([1-9]\d*|0)(\.\d{1,2})?$/,subsidy"></td>
													<td><input type="button" onclick="mallProductSubsidyModule.removeMjTd(this)" value="删除"/></td>
												</tr>
											</c:otherwise>
										</c:choose>
									</c:forEach>
								</table>
							</c:if>
						</td>
					</tr>
					<tr>
						<td align="right">
							<label class="Validform_label">
								开始时间:
							</label>
						</td>
						<td class="value">
							<input class="inputxt Wdate" name="starttime"  onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
								   value="<fmt:formatDate value='${subsidy.starttime}' type="date" pattern="yyyy-MM-dd HH:mm:ss"/>"  id="start_time"  datatype="*">
						</td>
						<td align="right">
							<label class="Validform_label">
								结束时间:
							</label>
						</td>
						<td class="value">
							<input class="inputxt Wdate" name="endtime"   onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" nullmsg="请填写结束时间"
								   value="<fmt:formatDate value='${subsidy.endtime}' type="date" pattern="yyyy-MM-dd HH:mm:ss"/>"  datatype="dataCompare" >
						</td>
					</tr>
				</table>
				<input type="hidden" name="productid" value="${mallProductPage.id }">
				<input type="hidden" name="index" id="index">
				<input type="button" id="save"  value="确认"/>
				<input type="hidden" id="is_look" value="${islook}">
				<input type="button" value="返回" id="back" onclick="javascript:history.back(-1)"/>
			</form>
			<link type="text/css" href="plug-in/Validform/css/metrole/style.css" rel="stylesheet">
			<link type="text/css" href="plug-in/Validform/css/metrole/tablefrom.css" rel="stylesheet">
			<script src="plug-in/Validform/js/Validform_v5.3.1_min_zh-cn.js" type="text/javascript"></script>
			<script src="plug-in/Validform/js/Validform_Datatype_zh-cn.js" type="text/javascript"></script>
			<script src="plug-in/Validform/js/datatype_zh-cn.js" type="text/javascript"></script>
			<script src="plug-in/Validform/plugin/passwordStrength/passwordStrength-min.js" type="text/javascript"></script>
			<script type="text/javascript">
				$(function() {
					mallProductSubsidyModule.init();
				});
				var mallProductSubsidyModule = (function(){
					//补贴改变
					var subsidyTypeChange = function(){
						$("#subsidyType").bind("change", function(){
							var val = $(this).val();
							var html = '';
							if(val == 0){
								html = '<input class="inputxt" id="subsidyVal" value="0" name="subsidyval" datatype="d">';
							}else if(val == 3){//满减
								html = '<table id="subsidyVal_table"> ' +
											'<tr>' +
											'<td>最小金额:<input class="inputxt" type="text" datatype="/^([1-9]\\d*|0)(\\.\\d{1,2})?$/" /><span class="Validform_checktip"></span></td>' +
											'<td>最大金额:<input class="inputxt" type="text"  datatype="/^([1-9]\\d*|0)(\\.\\d{1,2})?$/,maxMoneyCompare" /><span class="Validform_checktip"></span></td>' +
											'<td>补贴金额:<input class="inputxt" type="text"  datatype="/^([1-9]\\d*|0)(\\.\\d{1,2})?$/,subsidy" /><span class="Validform_checktip"></span></td>' +
											'<td><input type="button" onclick="mallProductSubsidyModule.addMjTd()" value="添加"/></td> ' +
											'</tr>' +
										'</table>'
							}else{//其他
								html = '<input class="inputxt" id="subsidyVal" nullmsg="请填写补贴额度"  name="subsidyval" datatype="/^([1-9]\\d*|0)(\\.\\d{1,2})?$/,subsidy"><span class="Validform_checktip"></span>';
							}
							$("#subsidyVal_td").html(html);
						})
					}
					//表单验证
					var fromValidform = function(){
						$("#subsidy").Validform({
							tiptype:4,
							btnSubmit:"#save",
							ajaxPost:true,
							datatype:{
								//时间验证
								"dataCompare":function(gets,obj,curform,regxp){
									var startTime = $("#start_time").val();
									if(gets <= startTime){
										return "结束时间不能小于开始时间!";
									}else{
										return true;
									}
								},
								//补贴金额验证
								"subsidy":function(gets,obj,curform,regxp){
									gets = parseFloat(gets);
									var subsidyType = parseInt($("#subsidyType").val());
									var isValid = true;
									var msg;
									switch (subsidyType){
										case 1://按金额
											var productType = parseInt($("#product_saletype").val());
											if(productType == 2){//虚拟商品不能大于最大充值金额
												var productMaxMoney = parseFloat($("#product_maxmoney").val());
												if(gets >= productMaxMoney){
													isValid = false;
													msg =  "补贴金额不能大于最大充值金额";
												}
											}else{//其他商品不能大于商品当前价
												var productPrice = parseFloat($("#product_price").val());
												if(gets >= productPrice){
													isValid = false;
													msg =  "补贴金额不能大于商品价格";
												}
											}
											break;
										case 2://按折扣 折扣不能大于100；
											if(gets >= 100){
												isValid = false;
												msg =  "折扣额度不能大于100";
											}
											break;
										case 3://满减 补贴金额小于最少和最大的差
											var tr = obj.parent().parent();
											var min = parseFloat($(tr).children("td").eq(0).children("input[type=text]").val());
											var max = parseFloat($(tr).children("td").eq(1).children("input[type=text]").val());
											var subtract = parseFloat(max - min);
											if(gets < subtract){

											}else{
												isValid = false;
												msg =  "补贴金额应小于最大最小金额差！";
											}
											break;
									}
									if(isValid){
										return true
									}else{
										return msg;
									}
								},
								//最大金额验证
								"maxMoneyCompare":function(gets,obj,curform,regxp){
									gets = parseFloat(gets);
									var tr = obj.parent().parent();
									var min = parseFloat($(tr).children("td").eq(0).children("input[type=text]").val());
									if(min >= gets){
										return "最大金额不能小于等于最大金额！";
									}else{
										return true;
									}
								},
								//最少金额验证
								"minMoneyCompare":function(gets,obj,curform,regxp){
									gets = parseFloat(gets);
									var lastTr = obj.parent().parent().prev();
									var lastMaxMoney = parseFloat($(lastTr).children("td").eq(1).children("input[type=text]").val());
									if(lastMaxMoney != gets){
										return "最小金额只能等于上一最大金额！";
									}else{
										return true;
									}
								},

							},
							beforeSubmit:function(){
								//先清除
								$("input[type=hidden][name^='minMoney_']").remove();
								$("input[type=hidden][name^='maxMoney_']").remove();
								$("input[type=hidden][name^='subsidyVal_']").remove();
								var vsubsidyType = $("#subsidyType").val();
								if(vsubsidyType == 3){//满减
									var tr = $("#subsidyVal_table tr");
									$("#index").val($(tr).length);
									$(tr).each(function(index){
										var minMoney = $(this).find("td input[type=text]").eq(0).val();
										var maxMoney = $(this).find("td input[type=text]").eq(1).val();
										var subsidyVal = $(this).find("td input[type=text]").eq(2).val();
										var minMoneyHtml = '<input type="hidden" value="'+minMoney+'" name="minMoney_'+index+'">'
										var maxMoneyHtml = '<input type="hidden" value="'+maxMoney+'" name="maxMoney_'+index+'">'
										var subsidyValHtml = '<input type="hidden" value="'+subsidyVal+'" name="subsidyVal_'+index+'">'
										$("#subsidy").append(minMoneyHtml);
										$("#subsidy").append(maxMoneyHtml);
										$("#subsidy").append(subsidyValHtml);
									});
								}
								return true;
							},
							callback:function(data){
								if(data.success==true){
									tip(data.msg);
									window.document.location.href  = 'mallProductController.do?managelist'
								}else{
									$.messager.alert('错误',data.msg);
								}
							}
						});
					}
					//是否查看
					var isLook = function(){
						var isLook = $("#is_look").val();
						if(isLook == 'true'){
							$(":input").attr("disabled",true);
							$("#back").attr("disabled",false);
						}else{
							$(":input").attr("disabled",false);
						}
					}
					var module = {
						init : function(){
							subsidyTypeChange();
							fromValidform();
							isLook();
						},
						//添加满减行
						addMjTd : function(){
							var html = '<tr>' +
											'<td>最小金额:<input class="inputxt"  type="text" datatype="/^([1-9]\\d*|0)(\\.\\d{1,2})?$/,minMoneyCompare" /><span class="Validform_checktip"></span></td>' +
											'<td>最大金额:<input class="inputxt" type="text"  datatype="/^([1-9]\\d*|0)(\\.\\d{1,2})?$/,maxMoneyCompare" /><span class="Validform_checktip"></span></td>' +
											'<td>补贴金额:<input class="inputxt" type="text" datatype="/^([1-9]\\d*|0)(\\.\\d{1,2})?$/,subsidy" /><span class="Validform_checktip"></span></td>' +
											'<td><input type="button" onclick="mallProductSubsidyModule.removeMjTd(this)" value="删除"/></td> ' +
										'</tr>'
							$("#subsidyVal_table").append(html);
						},
						//删除满减行
						removeMjTd : function(obj){
							$(obj).parent().parent().remove();
						},
					}
					return module;
				})();

			</script>
 </body>
